﻿using System.Activities.Presentation;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.Services;

namespace Headsight.BPMN2WF.WF.Impl
{
    public class WFWorkflowDesigner : AbstractDesigner
    {
        private readonly WorkflowDesigner _workflowDesigner;
        private readonly WFActivityDesigner _wfActivityDesigner;

        public WFWorkflowDesigner(WorkflowDesigner workflowDesigner)
        {
            _workflowDesigner = workflowDesigner;

            var modelService = workflowDesigner.Context.Services.GetService<ModelService>();
            var flowChartItem = modelService.Root.Properties["Implementation"].Value;
            var activityDesigner = flowChartItem.View as ActivityDesigner;

            // Get ActivityDesigner
            //var activityDesigner = FlowChartItem.InnerItem.View as ActivityDesigner;
            _wfActivityDesigner = new WFActivityDesigner(activityDesigner);
        }

        protected override EditingContext GetEditingContext()
        {
            return _workflowDesigner.Context;
        }

        private AbstractModelItem _flowChartItem;
        public AbstractModelItem FlowChartItem
        {
            get {
                return _flowChartItem ??
                       (_flowChartItem =
                        ModelItemFactory.Create(ModelService.Root.Properties["Implementation"].Value, ViewStateService, ViewService));
            }
        }

        public WorkflowDesigner WorkflowDesigner
        {
            get { return _workflowDesigner; }
        }

        public WFActivityDesigner WfActivityDesigner
        {
            get { return _wfActivityDesigner; }
        }
    }
}
